$(document).ready(function(){
	//QUICKSAND
	
		// get the action filter option item on page load
		  var $filterType = jQuery('.pf_categories li.active a,.pf_categories-sb li.active a').attr('class');
			
		  // get and assign the portfolio element to the
			// $holder varible for use later
		  var $holder = jQuery('ul.portfolio,ul.portfolio-sb');

		  // clone all items within the pre-assigned $holder element
		  var $data = $holder.clone();

		  // attempt to call Quicksand when a filter option
			// item is clicked
			jQuery('.pf_categories li a,.pf_categories-sb li a').click(function(e) {
				// reset the active class on all the buttons
				jQuery('.pf_categories li,.pf_categories-sb li').removeClass('active');
				
				// assign the class of the clicked filter option
				// element to our $filterType variable
				var $filterType = jQuery(this).attr('class');
				jQuery(this).parent().addClass('active');
				
				if ($filterType == 'all') {
					// assign all li items to the $filteredData var when
					// the 'All' filter option is clicked
					var $filteredData = $data.find('li');
				} 
				else {
					// find all li elements that have our required $filterType
					// values for the data-type element
					var $filteredData = $data.find('li[data-type~=' + $filterType + ']');
				}
				
				// call quicksand and assign transition parameters
				$holder.quicksand($filteredData, {
					duration: 800,
					easing: 'easeInOutQuad'
				}, function(){
					//REINIT ALL JQUERY STUFF!
				
					//PRELOADER HANDLE					
					jQuery('.portfolio li img,.portfolio-sb li img').each(function(){
						jQuery(this).css({'opacity':'1','visibility':'visible'});
					});					
					
										
					
					//FANCYBOX				
					jQuery('.fancybox').fancybox();
					jQuery('.fancybox_iframe').fancybox(
						{
							'width'				: '75%',
							'height'			: '75%',
							'autoScale'     	: false,
							'type'				: 'iframe'
						}
					);
					
					jQuery('.fancybox_embed').fancybox(
						{
							'hideOnContentClick': true
						}
					);
					
					
					var $vid_id = '';
					jQuery('.fancybox_flv').click(function(){
						var $vid_id = jQuery(this).attr('href');
						jQuery.fancybox(
						{						
							'href'	:	'swf/player_flv_maxi.swf',
							'autoScale'     	: true,
							'type'				: 'swf',						
							'swf'			: {
							'FlashVars'		: 'showvolume=1&amp;buttonovercolor=d3aa66&amp;sliderovercolor=d3aa66&amp;loadingcolor=ffffff&amp;autoplay=1&amp;flv='+$vid_id
							}
						});
						return false;
					});
					
					
								
				});
				return false;
			});	
	
});